<?php

namespace app\v1\controller;

use support\Request;
use app\model\Util;

class RefundController
{

    public function status(\support\Request $request)
    {
        $orderId = $request->get('order_id');
        if (!$orderId) {
            return json(['code' => 1, 'msg' => '缺少订单ID']);
        }

        // 假设 type = 'biz-order'，item_id = 订单ID
        $refund = \app\model\RefundRecordModel::where('type', 'biz-order')
            ->where('item_id', $orderId)
            ->orderBy('id', 'desc')
            ->first();

        if (!$refund) {
            return json(['code' => 2, 'msg' => '无退款记录']);
        }

        return json([
            'code' => 0,
            'msg' => 'ok',
            'data' => [
                'refund_amount' => $refund->refund_amount,
                'status' => $refund->status,
                'refund_at' => $refund->refund_at,
            ]
        ]);
    }
} 